import fs from 'fs';
import {BaseEvent, MetadataResponse, IEvent} from "../event-types";
import {DisplayPreparation} from "./display-preparation";
import {MousePreparation} from "./mouse-preparation";
import {DialogPreparation} from "./dialog-preparation";

export class DataPreparation {

    protected readonly metadata: MetadataResponse;

    constructor() {
        this.metadata = JSON.parse(fs.readFileSync('metadata.json').toString());
    }
    prepare(data: BaseEvent[]) : any[] {
        const displayEvent = new DisplayPreparation();
        const mouseEvent = new MousePreparation();
        const dialogEvent = new DialogPreparation();
        const displayEvents: IEvent[] = displayEvent.prepareDisplayEvents(data, this.metadata);
        const mouseEvents = mouseEvent.prepareMouseEvents(data, this.metadata);
        const dialogEvents = dialogEvent.prepareDialogContent(data, this.metadata);

        return displayEvents.concat(mouseEvents).concat(dialogEvents).sort((a, b) => a.timestamp - b.timestamp)
    }
}